package com.ffyc.ssm.controller;
import com.ffyc.ssm.common.CommonResult;

import com.ffyc.ssm.modle.User;
import com.ffyc.ssm.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path="/userLoginController")
public class UserLoginController {
    @Autowired
    UserLoginService userLoginService;
    @PostMapping(path="/register")
    public CommonResult Register(User user){
        CommonResult commonResult;
     try{
         userLoginService.Userregister(user);
         commonResult=new CommonResult(200,"注册成功",null);
     }catch(Exception e){
         e.printStackTrace();
         commonResult=new CommonResult(500,"服务器忙",null);
     }
     return commonResult;
    }

    @PostMapping(path="/login")
    public CommonResult Login(User user){
        CommonResult commonResult;
        try{
            User user1=userLoginService.Login(user);
            if(user1!=null){
                commonResult=new CommonResult(200,"登陆成功",user1);
            }else{
                commonResult=new CommonResult(201,"账号或密码错误",null);
            }
        }catch(Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(500,"服务器忙",null);
        }
        return commonResult;
    }
}
